{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# 条件运算符"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "- 三元运算符\n",
    "- 条件运算符在执行时先会对条件表达式进行求值判断\n",
    "    - 如果判断结果为 `True`，则执行语句 1 ，并返回执行结果\n",
    "    - 如果判断结果为 `False`，则执行语句 2，并返回执行结果"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('你好') if True else print('Hello')\n",
    "print('你好') if False else print('Hello')\n",
    "\n",
    "a = 10\n",
    "b = 20\n",
    "print('a 比较大') if a > b else print('b 比较大')\n",
    "\n",
    "max = a if a > b else b\n",
    "print(f'max = {max}')"
   ]
  },
  {
   "source": [
    "## 练习"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 80\n",
    "b = 110\n",
    "c = 30\n",
    "\n",
    "max = (a if a > c else c) if a > b else (b if b > c else c)\n",
    "print(f'max = {max}')"
   ]
  }
 ]
}